package com.sctvcloud.renhe.beans;

import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.google.gson.annotations.SerializedName;
import com.jiongbull.jlog.JLog;
import com.ruihang.generalibrary.ui.util.IListData;
import com.sctvcloud.renhe.ui.util.IListShowData;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by liuyu on 2017/9/11.
 */

public class FLiveDy implements ILiveDy {
    /**
     * content : 直播内容测试
     * id : 524
     * image : /sctv/1/image/public/201709/20170904143245_08pywqms70.jpg,
     * liveId : 404
     * time : 1505013531000
     * video : /sctv/1/video/public/201709/20170903183821_8oebmbluyo.mp4
     */

    private String content;
    @SerializedName("id")
    private int dyId;
    @SerializedName("image")
    private String dyImage;
    private String liveId;
    @SerializedName("time")
    private long dyTime;
    @SerializedName("video")
    private String dyVideo;

    private Date timeTemp;

    private List<ImageInfo> imageInfos;

    private int playedPos;

    @Override
    public String getDataTitle() {
        return null;
    }

    @Override
    public String getDataImg() {
        return null;
    }

    @Override
    public String getDataTag() {
        return null;
    }

    @Override
    public String getDataId() {
        return null;
    }

    @Override
    public int getDataType() {
        return 0;
    }

    @Override
    public int getDataViewType() {
        return 0;
    }

    @Override
    public IListData getOwner() {
        return null;
    }

    @Override
    public Date getDataDate() {
        if (timeTemp == null && dyTime > 0) {
            timeTemp = new Date(dyTime);
        }
        return timeTemp;
    }

    @Override
    public void setDataDate(Date date) {
    }

    @NonNull
    @Override
    public String getDatePattern() {
        return null;
    }

    @Override
    public String getDateString() {
        return "sdf";
    }

    @Override
    public String getTime() {
        return "sdf";
    }

    @Override
    public IListShowData getOwenerData() {
        return null;
    }

    @Override
    public List<ImageInfo> getContentImage() {
        if (imageInfos == null) {
            parseImages(0);
        }
        return imageInfos;
    }

    @Override
    public String getContentText() {
        return content;
    }

    @Override
    public String getDyVideoUrl() {
        return dyVideo;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public int getDyId() {
        return dyId;
    }

    public void setDyId(int dyId) {
        this.dyId = dyId;
    }

    public String getDyImage() {
        return dyImage;
    }

    public void setDyImage(String dyImage) {
        if (TextUtils.equals(this.dyImage, dyImage)) {
            imageInfos = null;
        }
        this.dyImage = dyImage;
    }

    public String getLiveId() {
        return liveId;
    }

    public void setLiveId(String liveId) {
        this.liveId = liveId;
    }

    public long getDyTime() {
        return dyTime;
    }

    public void setDyTime(long dyTime) {
        if (this.dyTime != dyTime) {
            timeTemp = null;
        }
        this.dyTime = dyTime;
    }

    public String getDyVideo() {
        return dyVideo;
    }

    public void setDyVideo(String dyVideo) {
        this.dyVideo = dyVideo;
    }

    private void parseImages(int w) {
        if (TextUtils.isEmpty(dyImage) || dyImage.length() <= 4) {
            JLog.e("qqsq  imge no valued  "+w+"   "+this+"  \n"+dyImage);
            return;
        }
        w=w*10+1;
        if (dyImage.startsWith(",")) {
            dyImage = dyImage.substring(1);
            parseImages(w);
            return;
        }
        w=w*100;
        String[] is = dyImage.split(",");
        imageInfos = new ArrayList<>();
        if (is == null || is.length == 0) {
            w++;
            imageInfos.add(new ImageInfo(dyImage));
        } else {
            w=w+2+is.length;
            for (int i = 0; i < is.length; i++) {
                if (!TextUtils.isEmpty(is[i])) {
                    imageInfos.add(new ImageInfo(is[i]));
                }
            }
        }
        JLog.e("qqsq   w="+w+"    "+this+"  "+imageInfos);
    }

    public int getPlayedPos() {
        return playedPos;
    }

    public void setPlayedPos(int playedPos) {
        this.playedPos = playedPos;
    }

    @Override
    public String toString() {
        return "FLiveDy@" +Integer.toHexString(hashCode())+"{"+
                "content='" + content + '\'' +
                ", dyId=" + dyId +
                ", dyImage='" + dyImage + '\'' +
                ", liveId='" + liveId + '\'' +
                ", dyTime=" + dyTime +
                ", dyVideo='" + dyVideo + '\'' +
                ", timeTemp=" + timeTemp +
                ", imageInfos=" + imageInfos +
                ", playedPos=" + playedPos +
                '}';
    }
}
